package com.atlassian.jira.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import org.apache.log4j.Logger;

import com.atlassian.core.user.UserUtils;
import com.atlassian.jira.resource.DefaultUser;
import com.opensymphony.user.EntityNotFoundException;

@Path("userandgroupservice")
public class DefaultUserAndGroupService implements UserAndGroupService {

	private static final Logger LOGGER = Logger.getLogger(DefaultUserAndGroupService.class);

	public DefaultUserAndGroupService() {
	}

	@GET
	@Path("/users/{username}")
	public DefaultUser getUser(@PathParam("username")
	String username) {

		DefaultUser user = null;

		try {
			com.opensymphony.user.User foundUser = UserUtils.getUser(username);
			user = new DefaultUser(foundUser);
		} catch (EntityNotFoundException enfe) {
			LOGGER.debug("Could not find user '" + username + "'", enfe);
			user = null;
		}

		return user;
	}
}
